<?php
class SeriesAction extends Action{
	public function index(){
		if(!empty($_GET['id'])){
			$seriesStr = new series();
			$storeModel = D("store");
			$seriesModel = D("series");
			$merchandiseModel = D("merchandise");
			$suser = $storeModel->join("suser on suser.suser_id = store.store_mid")
			->where("suser.suser_id='".trim($_GET['id'])."'")->find();
			
			$series = $seriesModel
			->where("series.series_sid='".$suser['store_id']."' and series_mid=''")->find();
			$commoditycount = 0;
			
			$seriescountArray = $series;
			$seriescount = count(array_filter($seriescountArray));
		
			
			$tempArray = array_chunk($series,28,true);
			//dump($tempArray);
			foreach($tempArray[1] as $key => $value){
				if($value==='0'){
					//$seriesShowArray[][$key] =  $value;
					//$seriesShowArray[][substr($key,0,8)] =  $tempArray[0][substr($key,0,8)];
					if(trim($tempArray[0][substr($key,0,8)])===''){
						$tmpValue = "商品系列".substr($key,7,1);
					}else{
						$tmpValue = trim($tempArray[0][substr($key,0,8)]);
					}
					$seriesShowArray[] = array($value,$tmpValue,substr($key,7,1));
				}
			}
			//dump($seriesShowArray);
			
			$this->assign("suser", $suser);
			$this->assign("series",$seriesShowArray);
			
			$this->assign('commoditycount',$commoditycount);
			$this->assign("seriescount",$seriescount-1);
			$this->display();
		}else{
			$this->redirect('Index/index');
		}
	}
	
	//显示商品列表
	public function showcommodityList(){
		if(!empty($_GET['id']) && !empty($_GET['level']) && !empty($_GET['series'])){
			$seriesStr = new series();
			$storeModel = D("store");
			$seriesModel = D("series");
			$merchandiseModel = D("merchandise");
			$mcd = $merchandiseModel->where("mcd_id='".trim($_GET['mcd_mid'])."'")->find();
			$suser = $storeModel->join("suser on suser.suser_id = store.store_mid")
			->where("suser.suser_id='".trim($_GET['id'])."'")->find();

			$newSeriesId = $_GET['mcd_mid']."_".$_GET['level'];
			if(empty($_GET['mcd_mid'])){
				$SeriesId = $suser['store_id'];
			}else{
				$SeriesId = $_GET['mcd_mid']."_".$_GET['level'];
			}

			$commodityList =  $merchandiseModel
					->where("mcd_sid='".$SeriesId."' and mcd_type='".$_GET['series']."' and mcd_mid='".trim($_GET['mcd_mid'])."'")->findAll();
			$this->assign('level',intval($_GET['level'])+1);
			$this->assign('mcd',$mcd);
			$this->assign("suser", $suser);
			$this->assign("commodityList", $commodityList);
			$this->display();
		}else{
			$this->redirect('index');
		}
	}
	
//显示商品信息
	public function showCommodity(){
		if(!empty($_GET['mcd_mid']) && !empty($_GET['id']) && !empty($_GET['showflag'])){
			$seriesStr = new series();
			$storeModel = D("store");
			$seriesModel = D("series");
			$merchandiseModel = D("merchandise");
			$mcd = $merchandiseModel->where("mcd_id='".trim($_GET['mcd_mid'])."'")->find();
			$suser = $storeModel->join("suser on suser.suser_id = store.store_mid")
			->where("suser.suser_id='".trim($_GET['id'])."'")->find();
			//dump($vo);
			//dump($_SESSION);
			$newSeriesId = $_GET['mcd_mid']."_".$_GET['level'];
			$series = $seriesModel
			->where("series_sid='".$newSeriesId."'")->find();

			$tempArray = array_chunk($series,28,true);
			//dump($tempArray);
			foreach($tempArray[1] as $key => $value){
				if($value==='0'){
					//$seriesShowArray[][$key] =  $value;
					//$seriesShowArray[][substr($key,0,8)] =  $tempArray[0][substr($key,0,8)];
					if(trim($tempArray[0][substr($key,0,8)])===''){
						$tmpValue = "商品系列".substr($key,7,1);
					}else{
						$tmpValue = trim($tempArray[0][substr($key,0,8)]);
					}
					$seriesShowArray[] = array($value,$tmpValue,substr($key,7,1));
				}
			}
			//dump($seriesShowArray);
			$this->assign('level',intval($_GET['level']));
			$this->assign('mcd',$mcd);
			$this->assign("suser", $suser);
			$this->assign("series",$seriesShowArray);
			if($_GET['showflag']=='I'){
				$this->display('showcommodityImg');
			}else{
				$this->display();
			}
		}else{
			//$this->redirect('index');
		}
	}
} 

//商品系列类
class series{	
	public $seriesStr=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
}
?>